/*
 * use sudo ./touchkeydemo open the /dev/input/event1
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <limits.h>
#include <termios.h>
#include <errno.h>
#include <linux/input.h>
//#include "log.h"
 
#define TOUCHKEY_TAG             "TouchkeyDemo "
#define TOUCHKEY_FILE            "/dev/input/event1"
 
int main(int argc, char **argv)
{
	int nFd;
	int nRet;
	struct input_event *sInputEvent;
	typedef int(*pfunc)(void);

	printf(" --> Make time: %s %s %s <-- \n", __DATE__, __TIME__, "Tony.Huang");
	
	sInputEvent = malloc(sizeof(struct input_event));
	nFd = open(TOUCHKEY_FILE, O_RDWR);
	if(nFd < 0)
	{
		printf("open file %s error.\n", TOUCHKEY_FILE);
		return -1;
	}
	else
	{
		printf("open file %s success.\n", TOUCHKEY_FILE);
	}
 
	int i = 50;
	while (i--) {
		printf("\n");
		memset(sInputEvent, 0, sizeof(struct input_event));
		nRet = read(nFd, sInputEvent, sizeof(struct input_event));
		if(nRet < 0)
		{
			printf("read file %s error.\n", TOUCHKEY_FILE);
			return nRet;
		}
	 
		printf("\ntype: 0x%x\t", sInputEvent->type);
		printf("code: 0x%x\t", sInputEvent->code);
		printf("value: 0x%x\t", sInputEvent->value);
	}
	free(sInputEvent);
	close(nFd);
	return 0;
}
